package com.rqf.ls.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.rqf.common.base.ProjectInfor;
import com.rqf.ls.service.IManagementAnalysisService;
import com.server.common.chart.ColumnVectorV2;
import com.server.web.JSONSerielizer;
import com.server.web.OutputUtil;

@Controller
@RequestMapping("analysis")
public class ManagementAnalysisController {
	
	@Autowired
	private IManagementAnalysisService analysisService;
	
	@RequestMapping("")
	public ModelAndView analysis(){
		ModelAndView mv = new ModelAndView("manager/analysis/analysis");
		mv.addObject("rootPath", ProjectInfor.ROOT_PATH);
		return mv;
	}
	/**
	 * 获取会计期间
	 * @param request
	 * @param response
	 * @author ServerZhang
	 * @date 2016年6月23日
	 */
	@RequestMapping("/month")
	public void month(HttpServletRequest request,HttpServletResponse response){
		List<Map<String, Object>> period = analysisService.getPeriod();
		OutputUtil.returnString(response, JSONSerielizer.toJson(period, null, null));
	}
	@RequestMapping("/chartData")
	public void chartData(HttpServletRequest request,HttpServletResponse response){
		String startPeriod = request.getParameter("startPeriod");
		String endPeriod = request.getParameter("endPeriod");
		ColumnVectorV2 userStatictics = analysisService.getUserStatictics(startPeriod, endPeriod);
		String[] exclude = new String[] { "*.class" };
		OutputUtil.returnString(response, JSONSerielizer.toJson(userStatictics,null,exclude));
	}
	@RequestMapping("/gridData1")
	public void gridData1(HttpServletRequest request,HttpServletResponse response){
		List<Map<String, Object>> pie1Data = analysisService.pie1Data();
		String json = JSONSerielizer.toJson(pie1Data, null, null);
		OutputUtil.returnString(response,json);
	}
	@RequestMapping("/gridData2")
	public void gridData2(HttpServletRequest request,HttpServletResponse response){
		List<Map<String, Object>> pieData = analysisService.pie2Data();
		String json = JSONSerielizer.toJson(pieData, null, null);
		OutputUtil.returnString(response,json);
	}
	@RequestMapping("/gridData3")
	public void gridData3(HttpServletRequest request,HttpServletResponse response){
		List<Map<String, Object>> pieData = analysisService.pie3Data();
		String json = JSONSerielizer.toJson(pieData, null, null);
		OutputUtil.returnString(response,json);
	}

}
